package com.ing5.BL.android.cinece;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ing5.BL.android.cinece.api.model.Information;

public class FavoriteListAdapter extends BaseAdapter {
    
    private List<Information> informations = null;
    private static LayoutInflater inflater=null;
    private static ViewHolder holder;
    
    public FavoriteListAdapter(Activity context, List<Information> informations) {
        this.informations=informations;
        inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
        return informations.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null){
            vi = inflater.inflate(R.layout.search_list, null);
            holder=new ViewHolder();
            holder.favoriteName=(TextView) vi.findViewById(R.id.item_name);
            holder.favoriteYear=(TextView) vi.findViewById(R.id.item_year);
        	vi.setTag(holder);
        }
        else holder=(ViewHolder) vi.getTag();
        holder.favoriteName.setText(informations.get(position).getTitle());
        holder.favoriteYear.setText(informations.get(position).getType() + " - " + informations.get(position).getYear());
        return vi;
    }
    
    public class ViewHolder {
    	TextView favoriteName;
    	TextView favoriteYear;
    }

}
